// packageA/pages/cleanWorkDetail/cleanWorkDetail.js
import CommonService from '../../../utils/service/commonService.js';
const util = require('../../../utils/util');
import Base64 from '../../../utils/Base64.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //传参
    paramObj:null,     
    //信息回显
    editInfo:{}  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { 
    if(options.paramObj){
      let paramObj=JSON.parse(options.paramObj);
      console.log('保洁工单详情传参');
      console.log(paramObj);

      this.setData({
        paramObj: paramObj
      })

      if(paramObj.id){
        //获取修改的数据
        this.getInfo();
      }
    }
  },

  //获取修改的数据
  getInfo(){
    let param = {
      isAuth: false,
      className: 'cleanKeepingOrder',
      data: {
        id:this.data.paramObj.id,
				selectFields: ['id','state','project','place','problem','submitter','submissionTime','remark','pic','handler','handlingTime','planCompletionTime','completionTime','handleResult','completionPic','evaluateScore','evaluateContent','checkTime'],
				nbl: Base64.encode(util.timeFormatDay(new Date()))
      }
    }

    CommonService.goFindList(param).then(res => {
      if(res.data.data && res.data.data.result && res.data.data.result.length) {
				let result=res.data.data.result[0];

        //状态
				switch(result.state){
					case 1:
						result.self_state='已完成';
						result.self_stateClass='c-2';
						break;
					case 2:
						result.self_state='待接单';
						result.self_stateClass='c-1';
						break;
					case 3:
						result.self_state='处理中';
						result.self_stateClass='c-3';
						break;
					case 4:
						result.self_state='待验收';
						result.self_stateClass='c-4';
						break;
				}

        //创建时间
        if(result.submissionTime){
          result.self_submissionTime=util.timeFormat(result.submissionTime);
				}			

				//开始处理时间
        if(result.handlingTime){
          result.self_handlingTime=util.timeFormat(result.handlingTime);
        }
			
				//预计完成时间
        if(result.planCompletionTime){
          result.self_planCompletionTime=util.timeFormat(result.planCompletionTime);
				}
				
        //实际完成时间
        if(result.completionTime){
          result.self_completionTime=util.timeFormat(result.completionTime);
				}
				
				//验收时间
        if(result.checkTime){
          result.self_checkTime=util.timeFormat(result.checkTime);
        }
				
        console.log('保洁工单详情');
        console.log(result);
       
        this.setData({
          editInfo: result
        })
      }
    }).catch((error) => {
    })
  },

  //预览图片
  onPreviewImage(e) {
    let detail = e.target.dataset.detail;
    let src = e.target.dataset.src;
    console.log(e);
    wx.previewImage({
      current: src,
      urls: detail
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})